package com.ls;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RoundRobinRule;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@MapperScan(basePackages = "com.ls.mapper")
@EnableFeignClients(basePackages = "com.ls") //激活openFeign
public class OrderApplication {
    public static void main(String[] args) throws InterruptedException {
        SpringApplication.run(OrderApplication.class, args);


    }

    /**
     * 创建一个RestTemplate对象，并添加到spring容器中
     */

    @Bean
    @LoadBalanced   //启动ribbon的负载均衡
    public RestTemplate initRestTemplate(){
        return new RestTemplate();
    }

    /**
     * 定义ribbon的负载均衡策略，这个是全局的，对所有的微服务都生效
     */
    @Bean
    public IRule rule(){
        return new RoundRobinRule();
    }


}
